<?php
	$parent = $menu->getNode()->getParent();
	$action = "";
	if($parent){
		if($parent->getNode()->isRoot()){
			$action = Route::Url('menu-list');
		}else{
			$action = Route::Url('menu-list',array('id' => $parent->id));
		}
	}
?>
<form method="post" action="<?php echo $action; ?>">
	<fieldset> 
		<p>
			<!--  
				<?php //echo $selectbox->render(); ?>
			-->
		</p>
	
		<p>
			
			<?php if($menu->state() === Doctrine_Record::STATE_CLEAN):?>
				<input type="hidden" name="id" value="<?php echo $menu->id; ?>"/>
				<input type="hidden" name="parent_id" value="<?php echo $parent->id; ?>" />
			<?php else: ?>
				<input type="hidden" name="parent_id" value="<?php echo $id; ?>" />
			<?php endif;?>
		</p>		

		<p>
			<label>Tên</label>
			<input class="text-input small-input" type="text" id="small-input" value="<?php echo $menu->name;?>" name="name" />
		</p>
		
		<p>

			<label>Liên kết</label>
			<input class="text-input large-input" type="text" id="large-input" value="<?php echo $menu->link; ?>" name="link" />
		</p>
		
        <p>
            <?php if($target && $target->count() > 0): ?>
            <label>Vị trí</label>
            <select name="position">
                <option value="after">Sau</option>
                <option value="before">Trước</option>
            </select>
            
            
            <?php 
                $sibling =  $menu->getNode()->getPrevSibling();
                if($sibling){
                    $sibling = $sibling->id;
                }else{
                    $sibling = count($target);
                }
            ?>
            
            <select name="target_id">
                
                <?php foreach($target as $key => $item): ?>
                    <?php if($menu->id != $item->id): ?>
                        <option <?php if($sibling == $item->id){echo 'selected';} ?> value="<?php echo $item->id; ?>"><?php echo $item->name; ?></option>
                    <?php endif; ?>
                <?php endforeach; ?>
            </select>
            <?php endif; ?>
        </p>
        
		<p>

			<label>Tùy chọn</label>
			<select name="target">
				<option <?php if($menu->target == '_self'){echo 'selected';} ?> value="_self">Self</option>
				<option <?php if($menu->target == '_parent'){echo 'selected';} ?> value="_parent">Parent</option>
				<option <?php if($menu->target == '_top'){echo 'selected';} ?> value="_top">Top</option>
				<option <?php if($menu->target == '_blank'){echo 'selected';} ?> value="_blank">Blank</option>
			</select>
		</p>

		<p>
			<label>Hoạt động ?</label>
			<input type="checkbox" name="active" value="1" <?php if($menu->active == 1){echo 'checked';}?> />
		</p>
		
		<p>
			<input class="button" type="submit" value="Lưu" />
		</p>
		
	</fieldset>
				
	<div class="clear"></div><!-- End .clear -->				
</form>